package com.jy.appmarket.screenlock.activity;

import com.jy.appmarket.R;
import com.jy.appmarket.screenlock.view.LockNumberView;
import com.jy.appmarket.screenlock.view.LockNumberView.OnLockNumberListener;
import com.umeng.analytics.MobclickAgent;

import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;



/**
 * 类说明：
 * 
 * @author jie.li
 * @date 2015-2-10
 * @version 1.0
 */
public class NumberLockActivity extends FragmentActivity  {

	public static final String NUMBER_LOCK = "number_lock";
	private int mType = -1;

	public static void startNumberLockActivity(Context c, int type) {
		Intent i = new Intent(c, NumberLockActivity.class);
		Bundle b = new Bundle();
		b.putInt(NUMBER_LOCK, type);
		i.putExtras(b);
		c.startActivity(i);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_number_lock_layout);

		Intent i = getIntent();
		Bundle b = i.getExtras();
		mType = b.getInt(NUMBER_LOCK);

		initView();
		
	}

	private void initView() {

		ActionBar actionBar = getActionBar();
		actionBar.setTitle("数字密码");
		actionBar.setDisplayUseLogoEnabled(false);
		actionBar.setDisplayShowHomeEnabled(false);
		actionBar.setDisplayHomeAsUpEnabled(true);
		
		LockNumberView numberView = new LockNumberView(this, mType);
		numberView.setOnLockNumberListener(new OnLockNumberListener() {

			@Override
			public void OnLockNumber(int result) {
				if (result == LockNumberView.OK) {
					setResult(RESULT_OK);
					finish();
				}
			}
		});
		LinearLayout layout = findViewById(R.id.layout);

		LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		layout.addView(numberView, param);
	}

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}
}
